package org.ajax.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.ajax.dao.CommdityDAO;
import org.ajax.dao.impl.CommdityDAOImpl;

import java.io.IOException;
import java.io.PrintWriter;

/*
 *
 *@author XCH
 *@date2024 - 11 - 20
 *
 */
@WebServlet("/delete")
public class DeleteServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        String id = req.getParameter("id");
        CommdityDAO dao = new CommdityDAOImpl();
        int result = dao.deleteGood(id);
        PrintWriter out = resp.getWriter();
        if (result > 0) {
            out.print("{\"success\": true}");
        } else {
            out.print("{\"success\": false}");
        }
        out.flush();
    }
}
